#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

template <typename T>
int RemoveValue(vector<T>& v,T num){
    int left=0;
    int right=v.size()-1;
    while(left<=right){
        //找到左边等于目标值的下标
        while(left<=right && v[left]!=num){
            ++left;
        }
        //找到右边不等于目标值的下标
        while(left<=right && v[right]==num){
            --right;
        }
        //让左边等于目标值的替换为不等于目标值的
        if(left<right){
            v[left++]=v[right--];
        }
    }
    return left;
}
template <typename T>
void prints(vector<T> &v){
    for_each(v.begin(),v.end(),[](T num){
        cout<<num<<" ";
    });
    cout<<endl;
}

int main(){
    vector<int> v={0,1,2,2,3,0,4,2};
    int num=RemoveValue(v,2);
    v.resize(num);
    prints(v);
    return 0;
}